﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Liquid.Collections;

namespace GapBufferTests {
	[TestClass]
	public class Position {
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void FilledMovingCursorFromEndToBeginingDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(4);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			var sequence = buffer.ToArray();
			buffer.Position = 0;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void FilledMovingCursorFromBeginingToEndDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(4);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 0;
			var sequence = buffer.ToArray();
			buffer.Position = buffer.Count;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void FilledMovingCursorFromMiddleToEndDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(4);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 2;
			var sequence = buffer.ToArray();
			buffer.Position = buffer.Count;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void FilledMovingCursorFromMiddleToBeginingDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(4);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 2;
			var sequence = buffer.ToArray();
			buffer.Position = 0;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void GappedMovingCursorFromEndToBeginingDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(8);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			var sequence = buffer.ToArray();
			buffer.Position = 0;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void GappedMovingCursorFromBeginingToEndDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(8);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 0;
			var sequence = buffer.ToArray();
			buffer.Position = buffer.Count;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void GappedMovingCursorFromMiddleToEndDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(8);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 2;
			var sequence = buffer.ToArray();
			buffer.Position = buffer.Count;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}

		[TestMethod]
		public void GappedMovingCursorFromMiddleToBeginingDoesntChangeSequence() {
			var buffer = new GapBuffer<int>(8);
			buffer.InsertRange(new int[] { 1, 2, 3, 4 });
			buffer.Position = 2;
			var sequence = buffer.ToArray();
			buffer.Position = 0;
			Assert.IsTrue(buffer.ToArray().SequenceEqual(sequence));
		}
	}
}
